package com.amikomgamedev.labirinhantu.state;

import org.andengine.entity.modifier.MoveYModifier;
import org.andengine.entity.scene.ITouchArea;
import org.andengine.input.touch.TouchEvent;

import com.amikomgamedev.labirinhantu.Server_Data;

import android.view.KeyEvent;

public class State_Game_Pause
	extends
	    State_Game_Win
{

    protected void create_Game_Pause()
    {
	// grafik.spr_Game_Pause_Bg.setVisible(true);

	float p_Y = (RES_HEIGHT - grafik.spr_Game_Pause_Bg.getHeight()) / 2;

	grafik.spr_Game_Pause_Bg.registerEntityModifier(new MoveYModifier(
		0.5f,
		grafik.spr_Game_Pause_Bg.getY(),
		p_Y));
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event)
    {
	if (State_Menu_Current == STATE_GAME_PAUSE)
	{
	    if (keyCode == KeyEvent.KEYCODE_BACK)
	    {
		grafik.spr_Game_Pause_Bg
			.registerEntityModifier(new MoveYModifier(
				0.5f,
				grafik.spr_Game_Pause_Bg.getY(),
				-grafik.spr_Game_Pause_Bg.getHeight()));
		// grafik.spr_Game_Pause_Bg.setVisible(false);
		State_Menu_Current = STATE_GAME_PLAY;
	    }
	}

	return super.onKeyUp(keyCode, event);
    }

    @Override
    public boolean onAreaTouched(
	    TouchEvent pSceneTouchEvent,
	    ITouchArea pTouchArea,
	    float pTouchAreaLocalX,
	    float pTouchAreaLocalY)
    {
	if (State_Menu_Current == STATE_GAME_PAUSE)
	{
	    for (int i = 0; i < grafik.lst_Game_Pause_Btn.size(); i++)
	    {
		if (pTouchArea.equals(grafik.lst_Game_Pause_Btn.get(i)))
		{
		    if (i == 0)
		    {
			grafik.spr_Game_Pause_Bg
				.registerEntityModifier(new MoveYModifier(
					0.5f,
					grafik.spr_Game_Pause_Bg.getY(),
					-grafik.spr_Game_Pause_Bg.getHeight()));
			
			// grafik.spr_Game_Pause_Bg.setVisible(false);
			State_Menu_Current = STATE_GAME_PLAY;
		    }
		    else if (i == 1)
		    {
			restartGame();
		    }
		    else if (i == 2)
		    {
			detachGame();
		    }
		}
	    }
	}

	return super.onAreaTouched(
		pSceneTouchEvent,
		pTouchArea,
		pTouchAreaLocalX,
		pTouchAreaLocalY);
    }
    

	
	@Override
	public synchronized void onPauseGame()
	{
	    if(State_Menu_Current == STATE_GAME_PAUSE)
		sound.stopGameBgm(Server_Data.getStage());
	    
	    super.onPauseGame();
	}
	
	@Override
	public synchronized void onResumeGame()
	{
	    if(State_Menu_Current == STATE_GAME_PAUSE)
		sound.playGameBgm(Server_Data.getStage());

	    super.onResumeGame();
	}
}
